package net.zjitc.common;

/**
 * @Author admin
 * @Date 2019/4/2 9:24
 */
public class ServiceResponse <E>{
    private int status; //状态
    private String message; //消息
    private E data; //数据


    public int getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public E getData() {
        return data;
    }

    private ServiceResponse(int status) {
        this.status = status;
    }

    private ServiceResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    private ServiceResponse(int status, E data) {
        this.status = status;
        this.data = data;
    }

    private ServiceResponse(int status, String message, E data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    /**
     * 响应成功
     * @param <E>
     * @return
     */
    public static <E> ServiceResponse createSuccessStatus(){
       return new ServiceResponse<>(ResponseCode.SUCEESS.getStatus());
    }


    /**
     * 响应状态，相应消息
     */

    public static <E> ServiceResponse createSuccssAndMessage(String message){
        return new ServiceResponse<>(ResponseCode.SUCEESS.getStatus(),message);
    }

    /**
     * 响应状态，相应数据
     */
    public static <E> ServiceResponse createSuccssAndDate(E data){
        return new ServiceResponse<>(ResponseCode.SUCEESS.getStatus(),data);
    }

    /**
     * 响应状态，相应数据 ,消息
     */

    public static <E> ServiceResponse createSuccssByMessageDate(String message,E data){
        return new ServiceResponse<>(ResponseCode.SUCEESS.getStatus(),message,data);
    }

    /**
     * 失败
     * @param <E>
     * @return
     */
    public static <E> ServiceResponse createErrorStatus(){
        return new ServiceResponse<>(ResponseCode.ERROR.getStatus());
    }

    /**
     * 响应状态，相应消息
     */

    public static <E> ServiceResponse createErrorMessage(String message){
        return new ServiceResponse<>(ResponseCode.ERROR.getStatus(),message);
    }

}
